﻿using Microsoft.Phone.Tasks;
using System;

namespace Smile.Mvvm.Service
{
    /// <summary>Service wich manage sharing on social networks, mails and SMS.</summary>
    public class ShareService:IShareService
    {
        public void ShareLink(string uriString, string title = "", string description = "")
        {
            var uri = new Uri(uriString, UriKind.Absolute);
            ShareLink(uri, title, description);
        }


        public void ShareLink(Uri uri, string title = "", string description = "")
        {
            ShareLinkTask shareLinkTask = new ShareLinkTask();
            shareLinkTask.Title = title;
            shareLinkTask.LinkUri = uri;
            shareLinkTask.Message = description;
            shareLinkTask.Show();
        }

        public void ShareByMail(
            string subject, 
            string message, 
            string to = "", 
            string cc = "", 
            string bcc = "")
        {
            EmailComposeTask emailComposeTask = new EmailComposeTask();

            emailComposeTask.Subject = subject;
            emailComposeTask.Body = message;

            if (!string.IsNullOrWhiteSpace(to))
            {
                emailComposeTask.To = to;
            }

            if (!string.IsNullOrWhiteSpace(cc))
            {
                emailComposeTask.Cc = cc;
            }

            if (!string.IsNullOrWhiteSpace(bcc))
            {
                emailComposeTask.Bcc = bcc;
            }

            emailComposeTask.Show();
        }
    }
}
